package com.anolesoft.amljmes.fortyone.controller;

import com.anolesoft.amljmes.fortyone.dto.MesStoveQualityDto;
import com.anolesoft.amljmes.fortyone.service.MesStoveQualityService;
import com.anolesoft.common.core.constant.HttpStatus;
import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.common.security.util.SecurityUtils;
import com.anolesoft.yr.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/messtovequality")
public class MesStoveQualityController {
    @Autowired
    public MesStoveQualityService mesStoveQualityService;
    //新增
    @PostMapping(value="/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public AjaxResult addMesStoveQuality(@RequestBody MesStoveQualityDto queryInfoDto){
        System.out.println(">>>>>>add");
        LoginUser loginUser = SecurityUtils.getLoginUser();
        queryInfoDto.setCjr(loginUser.getEmpUid());
        queryInfoDto.setFactoryId(loginUser.getFacCode());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, mesStoveQualityService.addMesStoveQuality(queryInfoDto));
    }

    //修改
    @PostMapping(value="/update", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public AjaxResult updateMesGjgyxxFkszInfoDto(@RequestBody MesStoveQualityDto queryInfoDto){
        System.out.println(">>>>>>update");
        return new AjaxResult(HttpStatus.SUCCESS,  Constants.QUERY_SUCCESS_MESSAGE,mesStoveQualityService.updateMesStoveQuality(queryInfoDto));
    }

    // 根据炉次编号查主键
    @PostMapping(value="/queryMesStoveQualityById",produces= MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public AjaxResult queryMesStoveQualityById(@RequestBody Map<String, String> map) {
        String StoveFabinfoObj = map.get("objuid");
        MesStoveQualityDto mesStoveQualityDto=mesStoveQualityService.queryMesStoveQualityById(StoveFabinfoObj);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,mesStoveQualityDto);
    }

    // 根据炉次id查制造记录条码
    @PostMapping(value="/queryMesStoveQualityByCode",produces= MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public AjaxResult queryMesStoveQualityByCode(@RequestBody Map<String, String> map) {
        String StoveFabinfoObj = map.get("objuid");
        List<MesStoveQualityDto> list = mesStoveQualityService.queryMesStoveQualityByCode(StoveFabinfoObj);
        AjaxResult success = AjaxResult.success();
        success.put("data", list);
        return success;
    }

}
